package com.ficus.road.maintain.controller;

import com.ficus.road.maintain.core.model.DiseaseType;
import com.ficus.road.maintain.core.model.IdResult;
import com.ficus.road.maintain.service.DiseaseTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RestController
public class DiseaseTypeController {
    @Autowired
    private DiseaseTypeService diseaseTypeService;

    //创建新的病害类型
    //diseaseType数据库没了？
    @RequestMapping(value = "/hitType",
            produces = {"application/json"},
            consumes = {"application/json"},
            method = RequestMethod.POST)
    public ResponseEntity<IdResult> createType(@Valid @RequestBody DiseaseType diseaseType) {
        String id = diseaseTypeService.createType(diseaseType);
        IdResult idResult = new IdResult(id);
        return new ResponseEntity<>(idResult, HttpStatus.OK);
    }

    //查询病害类型
    @RequestMapping(value = "/hitType/query",
            produces = {"application/json"},
            method = RequestMethod.GET)
    public ResponseEntity<List<DiseaseType>> weatherSearch() {
        return new ResponseEntity<>(diseaseTypeService.list(), HttpStatus.OK);
    }
}
